package org.example.common.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.example.pinda.base.BaseEnum;

@Getter
@AllArgsConstructor
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum HttpMethod implements BaseEnum {
    GET("GET"),
    POST("POST"),
    PUT("PUT"),
    DELETE("DELETE"),
    PATCH("PATCH"),
    TRACE("TRACE"),
    HEAD("HEAD"),
    OPTIONS("OPTIONS");

    private final String desc;

    public static HttpMethod match(String val, HttpMethod def) {
        for (HttpMethod httpMethod : HttpMethod.values()) {
            if (httpMethod.name().equalsIgnoreCase(val)) {
                return httpMethod;
            }
        }
        return def;
    }

    public static HttpMethod get(String val) {
        return match(val, null);
    }

}
